package com.ruoyi.project.king.noticeType.controller;

import java.util.List;

import com.ruoyi.project.king.noticeType.domain.CmsNoticeType;
import com.ruoyi.project.king.noticeType.service.ICmsNoticeTypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 公告Controller
 * 
 * @author ruoyi
 * @date 2020-05-21
 */
@Controller
@RequestMapping("/system/type")
public class CmsNoticeTypeController extends BaseController
{
    private String prefix = "cms/noticeType/";

    @Autowired
    private ICmsNoticeTypeService cmsNoticeTypeService;

    @RequiresPermissions("system:type:view")
    @GetMapping()
    public String type()
    {
        return prefix + "/type";
    }

    /**
     * 查询公告列表
     */
    @RequiresPermissions("system:type:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CmsNoticeType cmsNoticeType)
    {
        startPage();
        List<CmsNoticeType> list = cmsNoticeTypeService.selectCmsNoticeTypeList(cmsNoticeType);
        return getDataTable(list);
    }

    /**
     * 导出公告列表
     */
    @RequiresPermissions("system:type:export")
    @Log(title = "公告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CmsNoticeType cmsNoticeType)
    {
        List<CmsNoticeType> list = cmsNoticeTypeService.selectCmsNoticeTypeList(cmsNoticeType);
        ExcelUtil<CmsNoticeType> util = new ExcelUtil<CmsNoticeType>(CmsNoticeType.class);
        return util.exportExcel(list, "type");
    }

    /**
     * 新增公告
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存公告
     */
    @RequiresPermissions("system:type:add")
    @Log(title = "公告", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CmsNoticeType cmsNoticeType)
    {
        return toAjax(cmsNoticeTypeService.insertCmsNoticeType(cmsNoticeType));
    }

    /**
     * 修改公告
     */
    @GetMapping("/edit/{tid}")
    public String edit(@PathVariable("tid") Long tid, ModelMap mmap)
    {
        CmsNoticeType cmsNoticeType = cmsNoticeTypeService.selectCmsNoticeTypeById(tid);
        mmap.put("cmsNoticeType", cmsNoticeType);
        return prefix + "/edit";
    }

    /**
     * 查看公告
     */
    @GetMapping("/show/{tid}")
    public String show(@PathVariable("tid") Long tid, ModelMap mmap)
    {
        CmsNoticeType cmsNoticeType = cmsNoticeTypeService.selectCmsNoticeTypeById(tid);
        mmap.put("cmsNoticeType", cmsNoticeType);
        return prefix + "/show";
    }

    /**
     * 修改保存公告
     */
    @RequiresPermissions("system:type:edit")
    @Log(title = "公告", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CmsNoticeType cmsNoticeType)
    {
        return toAjax(cmsNoticeTypeService.updateCmsNoticeType(cmsNoticeType));
    }

    /**
     * 删除公告
     */
    @RequiresPermissions("system:type:remove")
    @Log(title = "公告", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cmsNoticeTypeService.deleteCmsNoticeTypeByIds(ids));
    }
}
